package slw.controls
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.ui.Mouse;
	import flash.ui.MouseCursor;
	
	import slw.core.UIComponent;
	import slw.events.LoaderEvent;
	
	
	/**
	 * QTextField
	 * 文本组件类，支持影片皮肤，获得焦点换肤和边框
	 * <p>
	 * 	<listing>
	 * 		var t:QTextField=new QTextField("This is a component QTextField.");
			this.addChild(t);
			t.move(100,100);
			
			t.focusedActive=true;
			t.border=true;
			t.borderColor=0x0099CC;
			t.borderAlpha=0.6;
			t.defaultTextFormat=new TextFormat(null,12,0x0);
			t.displayStates=array;
			
			t.border=true;
			t.background=true;
			t.multiline=true;
			
			function getDisplay():Sprite{
				var s:Sprite=new Sprite();
				s.graphics.beginFill(0xcccccc+Math.random()*0xffffff,1);
				s.graphics.drawRect(0,0,100,100);
				s.graphics.endFill();
				
				return s;
			}
	 * 	</listing>
	 * </p>
	 * @author ddx<br/>
	 * 2011-7-19
	 *
	 */
	public class QTextField extends UIComponent
	{
		/**
		 * "normal",组件常规状态 
		 */		
		public static const NORMAL:String="normal";
		/**
		 * "focused",组件获得焦点状态
		 */		
		public static const FOCUSED:String="focused";
		//状态，自动大小
		private var _state:String=NORMAL;
		private var _autoSize:String=TextFieldAutoSize.NONE;
		
		//状态数组
		private var _displayStates:Array=[];
		//获得焦点滤镜
		private var _focusedFilters:Array=[new GlowFilter(0x0099CC,1,2,2,2,3,false,false)];
		
		//文本对象，边框容器，背景容器，状态容器
		private var _textField:TextField;
		private var _borderContainer:Sprite;
		private var _bgContainer:Sprite;
		private var _stateContainer:Sprite;
		
		//文本，html文本，可输入文本
		private var _text:String;
		private var _htmlText:String;
		private var _restrict:String;
		
		//是否自动换行,显示为多行，显示边框，焦点激活，显示背景，可编辑,显示为密码
		private var _wordWrap:Boolean;
		private var _multiline:Boolean;
		private var _border:Boolean;
		private var _focusedActive:Boolean;
		private var _background:Boolean;
		private var _editabled:Boolean;
		private var _displayAsPassword:Boolean;
		
		//文本颜色，边框颜色，边框alpha，边框圆角大小，背景颜色，背景alpha
		private var _textColor:uint=0x0;
		private var _borderColor:uint=0x0099CC;
		private var _borderAlpha:Number=0.6;
		private var _backgroundColor:uint=0xeeeeee;
		private var _backgroundAlpha:Number=1;
		
		//默认文本格式
		private var _defaultFormat:TextFormat;
		
		//组件高宽
		private var _width:Number=0;
		private var _height:Number=0;
		//文本与组件边界的距离
		private var _padding:Number=2;
		/**
		 * 构造函数 
		 * @param text:String="" 显示的文本
		 * 
		 */		
		public function QTextField(text:String="")
		{
			super();
			this.listName="QTextField";
			
			init();
			
			setSize(100,100);
			this.text=text;
			this.round=10;
		}
		
		/*
		-----------------------------------
		setters getters
		-----------------------------------
		*/
		//
		/**
		 * 组件显示的文本，同TextField.text 
		 * @param value:String
		 * 
		 */		
		public function set text(value:String):void{
			if(_text==value)return;
			
			_text=value;
			_htmlText=null;
			
			if(_autoSize!=TextFieldAutoSize.NONE){
				this.width=_textField.width+_padding*2;
				this.height=_textField.height+_padding*2;
			}else{
				updateDisplayList();
			}
		}
		//
		/**
		 * 组件显示的文本，同TextField.text 
		 * @param value:String
		 * 
		 */	
		public function get text():String{
			return _text;
		}
		//
		/**
		 * 组件显示的html文本，同TextField.htmlText 
		 * @param value:String
		 * 
		 */		
		public function set htmlText(value:String):void{
			if(_htmlText==value)return;
			
			_htmlText=value;
			_text=null;
			
			if(_autoSize!=TextFieldAutoSize.NONE){
				this.width=_textField.width+_padding*2;
				this.height=_textField.height+_padding*2;
			}else{
				updateDisplayList();
			}
		}
		//
		/**
		 * 组件显示的html文本，同TextField.htmlText 
		 * @param value:String
		 * 
		 */
		public function get htmlText():String{
			return _htmlText;
		}
		//
		/**
		 * 是否显示为多行,默认值:false 
		 * @param value:Boolean
		 * 
		 */		
		public function set multiline(value:Boolean):void{
			if(_multiline==value)return;
			
			_multiline=value;
			
			_textField.multiline=_multiline;
			
			if(_autoSize!=TextFieldAutoSize.NONE){
				this.width=_textField.width+_padding*2;
				this.height=_textField.height+_padding*2;
			}else{
				updateDisplayList();
			}
		}
		//
		/**
		 * 是否显示为多行,默认值:false 
		 * @param value:Boolean
		 * 
		 */	
		public function get multiline():Boolean{
			return _multiline;
		}
		//
		/**
		 * 是否自动换行，同TextField.wordWrap ,默认值:false
		 * @param value:Boolean
		 * 
		 */		
		public function set wordWrap(value:Boolean):void{
			if(_wordWrap==value)return;
			
			_wordWrap=value;
			
			_textField.wordWrap=_wordWrap;
			
			if(_autoSize!=TextFieldAutoSize.NONE){
				this.width=_textField.width+_padding*2;
				this.height=_textField.height+_padding*2;
			}else{
				updateDisplayList();
			}
		}
		//
		/**
		 * 是否自动换行，同TextField.wordWrap ,默认值:false
		 * @param value:Boolean
		 * 
		 */	
		public function get wordWrap():Boolean{
			return _wordWrap;
		}
		//
		/**
		 * 是否显示边框，默认值:false 
		 * @param value:Boolean
		 * 
		 */		
		public function set border(value:Boolean):void{
			if(_border==value)return;
			
			_border=value;
			
			if(_border&&_borderContainer==null){
				_borderContainer=new Sprite();
				_borderContainer.mouseEnabled=false;
				this.addChild(_borderContainer);
				
				if(_border)
					drawBorder(_borderContainer,_borderColor,_borderAlpha,this.width-1,this.height-1,this.round);
				
				if(_state==FOCUSED)setState(_state);
			}else if(_borderContainer!=null){
				this.removeChild(_borderContainer);
				_borderContainer=null;
			}
		}
		//
		/**
		 * 是否显示边框，默认值:false 
		 * @param value:Boolean
		 * 
		 */
		public function get border():Boolean{
			return _border;
		}
		//
		/**
		 * 边框颜色，默认值:0x0099CC
		 * @param value:uint
		 * 
		 */		
		public function set borderColor(value:uint):void{
			if(_borderColor==value)return;
			
			_borderColor=value;
			
			if(_border)
				drawBorder(_borderContainer,_borderColor,_borderAlpha,this.width-1,this.height-1,this.round);
		}
		//
		/**
		 * 边框颜色，默认值:0x0099CC
		 * @param value:uint
		 * 
		 */
		public function get borderColor():uint{
			return _borderColor;
		}
		//
		/**
		 * 边框颜色透明度，默认值:0.6 
		 * @param value:Number
		 * 
		 */
		public function set borderAlpha(value:Number):void{
			if(_borderAlpha==value)return;
			
			_borderAlpha=value;
			
			if(_border)
				drawBorder(_borderContainer,_borderColor,_borderAlpha,this.width-1,this.height-1,this.round);
		}
		//
		/**
		 * 边框颜色透明度,默认值:0.6 
		 * @param value:Number
		 * 
		 */
		public function get borderAlpha():Number{
			return _borderAlpha;
		}
		//
		/**
		 * 圆角大小，此属性影响边框和通过设置displayStates改变状态的显示对象可视范围(即圆角处无法看到显示对象)，
		 * 但不影响到皮肤，因皮肤属性skin由父类实现，因此若通过皮肤设置状态，应将皮肤圆角与圆角设置一致，默认值:10px 
		 * @param value:Number
		 * 
		 */		
		override public function set round(value:Number):void{
			if(this.round==value)return;
			
			super.round=value;
			
			if(_border)
				drawBorder(_borderContainer,_borderColor,_borderAlpha,this.width-1,this.height-1,this.round);
			if(_background)
				drawRect(_bgContainer,0,_backgroundColor,_backgroundAlpha,0,0,this.width,this.height,this.round,true);
		}
		//
		/**
		 * 是否显示组件背景，默认值:false 
		 * @param value:Boolean
		 * 
		 */		
		public function set background(value:Boolean):void{
			if(_background==value)return;
			
			_background=value;
			
			if(_background){
				if(_bgContainer==null){
					_bgContainer=new Sprite();
					_bgContainer.mouseEnabled=false;
					this.buildContainer.addChildAt(_bgContainer,0);
				}
			}else if(_bgContainer!=null){
				this.buildContainer.removeChild(_bgContainer);
				_bgContainer==null;
			}
			
			if(_background)
				drawRect(_bgContainer,0,_backgroundColor,_backgroundAlpha,0,0,this.width,this.height,this.round,true);
		}
		//
		/**
		 * 是否显示组件背景，默认值:false 
		 * @param value:Boolean
		 * 
		 */	
		public function get background():Boolean{
			return _background;
		}
		//
		/**
		 * 背景颜色，默认值:0xeeeeee 
		 * @param value:uint
		 * 
		 */		
		public function set backgroundColor(value:uint):void{
			if(_backgroundColor==value)return;
			
			_backgroundColor=value;
			
			if(_background)
				drawRect(_bgContainer,0,_backgroundColor,_backgroundAlpha,0,0,this.width,this.height,this.round,true);
		}
		//
		/**
		 * 背景颜色，默认值:0xeeeeee
		 * @param value:uint
		 * 
		 */
		public function get backgroundColor():uint{
			return _backgroundColor;
		}
		//
		/**
		 * 背景透明度,默认值:0.2 
		 * @param value:Number
		 * 
		 */		
		public function set backgroundAlpha(value:Number):void{
			if(_backgroundAlpha==value)return;
			
			_backgroundAlpha=value;
			
			if(_background)
				drawRect(_bgContainer,0,_backgroundColor,_backgroundAlpha,0,0,this.width,this.height,this.round,true);
		}
		//
		/**
		 * 背景透明度,默认值:0.2 
		 * @param value:Number
		 * 
		 */
		public function get backgroundAlpha():Number{
			return _backgroundAlpha;
		}
		//
		/**
		 * 文本颜色，默认值:0x0,同TextField.textColor 
		 * @param value:uint
		 * 
		 */		
		public function set textColor(value:uint):void{
			if(_textColor==value)return;
			
			_textColor=value;
			_textField.textColor=_textColor;
		}
		//
		/**
		 * 文本颜色，默认值:0x0,同TextField.textColor 
		 * @param value:uint
		 * 
		 */
		public function get textColor():uint{
			return _textColor;
		}
		//
		/**
		 * 默认文本格式,设置为null时值为new TextFormat(null,12,0x0,false,false,false,"","","left",0,0,0,0) 
		 * @param value:TextFormat
		 * 
		 */		
		public function set defaultTextFormat(value:TextFormat):void{
			if(_defaultFormat==value)return;
			
			_defaultFormat=value;
			if(_defaultFormat==null)
				_defaultFormat=new TextFormat(null,12,0x0,false,false,false,"","","left",0,0,0,0);
			
			if(_autoSize!=TextFieldAutoSize.NONE){
				this.width=_textField.width+_padding*2;
				this.height=_textField.height+_padding*2;
			}else{
				updateDisplayList();
			}
		}
		//
		/**
		 * 默认文本格式,设置为null时值为new TextFormat(null,12,0x0,false,false,false,"","","left",0,0,0,0) 
		 * @param value:TextFormat
		 * 
		 */	
		public function get defaultTextFormat():TextFormat{
			return _defaultFormat;
		}
		//
		/**
		 * 是否自动适应文本宽高，默认值:TextFieldAutoSize.NONE，同TextField.autoSize
		 * @param value:String
		 * 
		 */		
		public function set autoSize(value:String):void{
			if(_autoSize==value)return;
			
			_autoSize=value;
			_textField.autoSize=_autoSize;
			
			if(_autoSize!=TextFieldAutoSize.NONE){
				this.width=_textField.width+_padding*2;
				this.height=_textField.height+_padding*2;
				
				_textField.addEventListener(Event.CHANGE,textFieldChange);
			}else{
				updateDisplayList();
				_textField.removeEventListener(Event.CHANGE,textFieldChange);
			}
		}
		//
		/**
		 * 是否自动适应文本宽高，默认值:TextFieldAutoSize.NONE，同TextField.autoSize
		 * @param value:String
		 * 
		 */
		public function get autoSize():String{
			return _autoSize;
		}
		//
		/**
		 * 指示用户可输入到文本字段中的字符集，默认值:null，同TextField.restrict
		 * @param value:String
		 * 
		 */		
		public function set restrict(value:String):void{
			if(_restrict==value)return;
			
			_restrict=value;
			_textField.restrict=_restrict;
			
			updateDisplayList();
		}
		//
		/**
		 * 指示用户可输入到文本字段中的字符集，默认值:null，同TextField.restrict
		 * @param value:String
		 * 
		 */
		public function get restrict():String{
			return _restrict;
		}
		//
		/**
		 * 组件是否可编辑，默认值:false 
		 * @param value:Boolean
		 * 
		 */		
		public function set editabled(value:Boolean):void{
			if(_editabled==value)return;
			
			_editabled=value;
			
			if(_editabled){
				_textField.type=TextFieldType.INPUT;
			}else{
				_textField.type=TextFieldType.DYNAMIC;
			}
		}
		//
		/**
		 * 组件是否可编辑，默认值:false 
		 * @param value:Boolean
		 * 
		 */
		public function get editabled():Boolean{
			return _editabled;
		}
		//
		/**
		 * 组件是否显示为密码，默认值:false,同TextField.displayAsPassword
		 * @param value:Boolean
		 * 
		 */		
		public function set displayAsPassword(value:Boolean):void{
			if(_displayAsPassword==value)return;
			
			_displayAsPassword=value;
			
			_textField.displayAsPassword=_displayAsPassword;
			
			updateDisplayList();
		}
		//
		/**
		 * 组件是否显示为密码，默认值:false,同TextField.displayAsPassword
		 * @param value:Boolean
		 * 
		 */
		public function get displayAsPassword():Boolean{
			return _displayAsPassword;
		}
		//
		/**
		 * 获得焦点是否改变状态,,若skin中有影片类，则影片的第1和2帧分别表示常规状态和焦点状态,
		 * 设置displayStates时displayStates[0]和displayStates[1]分别表示常规状态和焦点状态,默认值:false 
		 * @param value:Boolean
		 * 
		 */	
		public function set focusedActive(value:Boolean):void{
			if(_focusedActive==value)return;
			
			_focusedActive=value;
			if(_focusedActive){
				_textField.addEventListener(FocusEvent.FOCUS_IN,textFieldFocusIn);
				_textField.addEventListener(FocusEvent.FOCUS_OUT,textFieldFocusOut);
			}else{
				_textField.removeEventListener(FocusEvent.FOCUS_IN,textFieldFocusIn);
				_textField.removeEventListener(FocusEvent.FOCUS_OUT,textFieldFocusOut);
			}
			
			if(_state==FOCUSED)setState(_state);
		}
		//
		/**
		 * 获得焦点是否改变状态,,若skin中有影片类，则影片的第1和2帧分别表示常规状态和焦点状态,
		 * 设置displayStates时displayStates[0]和displayStates[1]分别表示常规状态和焦点状态,默认值:false 
		 * @param value:Boolean
		 * 
		 */	
		public function get focusedActive():Boolean{
			return _focusedActive;
		}
		//
		/**
		 * 文本与组件边界的距离，默认值:2px 
		 * @param value:Number
		 * 
		 */		
		public function set padding(value:Number):void{
			if(_padding==value) return;
			
			_padding=value;
			_padding=Math.max(_padding,0);
			
			_textField.x=_padding;
			_textField.y=_padding;
			_textField.width=_width-_padding*2;
			_textField.height=_height-_padding*2;
			
			updateDisplayList();
		}
		//
		/**
		 * 文本与组件边界的距离，默认值:2px 
		 * @param value:Number
		 * 
		 */
		public function get padding():Number{
			return _padding;
		}
		//
		/**
		 * 组件是否为舞台焦点 
		 * @param value:Boolean
		 * 
		 */				
		override public function set focused(value:Boolean):void{
			if(this.focused==value)return;
			
			if(value){
				this.stage.focus=_textField;
				_textField.setSelection(_textField.length,_textField.length);
			}else{
				this.stage.focus=null;
			}
		}
		//
		/**
		 * 组件是否为舞台焦点 
		 * @param value:Boolean
		 * 
		 */	
		override public function get focused():Boolean{
			return this.stage==null?false:this.stage.focus==_textField;
		}
		//
		/**
		 * focusedActive为true时，边框的滤镜，默认值:[new GlowFilter(0x0099CC,1,2,2,2,3,false,false)]
		 * @param value:Array
		 * 
		 */		
		public function set focusedFilters(value:Array):void{
			if(_focusedFilters==value)return;
			
			_focusedFilters=value;
			
			if(_state==FOCUSED)setState(_state);
		}
		//
		/**
		 * focusedActive为true时，边框的滤镜，默认值:[new GlowFilter(0x0099CC,1,2,2,2,3,false,false)]
		 * @param value:Array
		 * 
		 */	
		public function get focusedFilters():Array{
			return _focusedFilters;
		}
		//
		/**
		 * 指定组件在常规状态和焦点状态下的两种显示状态，数组元素应为DisplayObject子类，若传递的数组长度大于2，将被截断，默认值:[]
		 * @param value:Array
		 * 
		 */		
		public function set displayStates(value:Array):void{
			if(_displayStates==value)return;
			
			_displayStates=value;
			
			if(_displayStates==null||_displayStates.length==0){
				if(_stateContainer!=null){
					this.buildContainer.removeChild(_stateContainer);
					_stateContainer=null;
				}
			}else{
				_displayStates.length=Math.min(_displayStates.length,2);
				if(_stateContainer==null){
					_stateContainer=new Sprite();
					_stateContainer.mouseChildren=false;
					this.buildContainer.addChildAt(_stateContainer,0);
				}
				setState(_state);
				
				if(this.autoSizeBySkin){
					this.width=_stateContainer.width;
					this.height=_stateContainer.height;
				}
			}
		}
		//
		/**
		 * 指定组件在常规状态和焦点状态下的两种显示状态，数组元素应为DisplayObject子类，若传递的数组长度大于2，将被截断，默认值:[]
		 * @param value:Array
		 * 
		 */
		public function get displayStates():Array{
			return _displayStates;
		}
		//
		/**
		 * 外部皮肤url数组，加载成功时，资源根显示对象被添加到皮肤容器,并作为组件的两种状态，若传递的数组长度大于2，将被截断，默认值:[]
		 * @param value:Array
		 * 
		 */		
		override public function set displayURLs(value:Array):void{
			if(this.displayURLs==value)return;
			
			this.addEventListener(LoaderEvent.LOAD_COMPLETE,thisLoadComplete);
			super.displayURLs=value;
		}
		//
		override public function set width(value:Number):void{
			if(_autoSize!=TextFieldAutoSize.NONE){
				value=_textField.width;
			}
			super.width=value;
			if(_width==value){
				return;
			}
			_width=value;
			
			_textField.width=value-_padding*2;
			
			if(_border)
				drawBorder(_borderContainer,_borderColor,_borderAlpha,this.width-1,this.height-1,this.round);
		}
		//
		override public function set height(value:Number):void{
			if(_autoSize!=TextFieldAutoSize.NONE){
				value=_textField.height;
			}
			super.height=value;
			if(_height==value){
				return;
			}
			_height=value;
			
			_textField.height=value-_padding*2;
			
			if(_border)
				drawBorder(_borderContainer,_borderColor,_borderAlpha,this.width-1,this.height-1,this.round);
		}
		//
		/**
		 * 组件文本对象 
		 * 
		 */		
		public function get textField():TextField{
			return _textField;
		}
		/*
		-----------------------------------
		public  methods
		-----------------------------------
		*/
		//
		/**
		 * 设置文本格式，同TextField.setTextFormat 
		 * @param format:TextFormat
		 * @param startIndex:int=0
		 * @param endIndex:int=int.MAX_VALUE
		 * 
		 */		
		public function setTextFormat(format:TextFormat,startIndex:int=0,endIndex:int=int.MAX_VALUE):void{
			_textField.setTextFormat(format,startIndex,endIndex);
		}
		//
		override public function destroy():void{
			_textField.removeEventListener(FocusEvent.FOCUS_IN,textFieldFocusIn);
			_textField.removeEventListener(FocusEvent.FOCUS_OUT,textFieldFocusOut);
			_textField.removeEventListener(Event.CHANGE,textFieldChange);
			
			this.removeEventListener(LoaderEvent.LOAD_COMPLETE,thisLoadComplete);
			super.destroy();
		}
		/*
		-----------------------------------
		private  methods
		-----------------------------------
		*/
		//初始化
		private function init():void{
			this.mouseChildren=true;
			
			_textField=new TextField();
			_textField.x=_padding;
			_textField.y=_padding;
			this.buildContainer.addChild(_textField);
			
			_defaultFormat=new TextFormat(null,12,0x0,false,false,false,"","","left",0,0,0,0);
		}
		//更新显示
		private function updateDisplayList():void{
			if(_defaultFormat!=null){
				_textField.defaultTextFormat=_defaultFormat;
			}
			if(_text!=null){
				_textField.text=_text;
			}else if(_htmlText!=null){
				_textField.htmlText=_htmlText;
			}
			
			if(_borderContainer!=null)
				this.setChildIndex(_borderContainer,this.numChildren-1);
		}
		//设置状态
		private function setState(state:String):void{
			if(!_focusedActive){
				return;
			}
			switch(state){
				case NORMAL:
					showState(0);
					break;
				case FOCUSED:
					showState(1);
					break;
				default:
					throw new Error("QTextField 状态值应为:["+NORMAL+","+FOCUSED+"]之一");
			}
		}
		//显示状态
		private function showState(index:int):void{
			var $targets:Array=this.skinTargets;
			for(var i:int=0;i<$targets.length;i++){
				if(($targets[i] as MovieClip)!=null){
					MovieClip($targets[i]).gotoAndStop(index+1);
				}
			}
			
			if(_displayStates[index] is DisplayObject){
				if(_stateContainer!=null){
					while(_stateContainer.numChildren>0){
						_stateContainer.removeChildAt(0);
					}
					_stateContainer.addChild(_displayStates[index]);
				}
			}
			
			if(_border){
				if(index==0){
					if(_borderContainer!=null)_borderContainer.filters=[];
				}else if(index==1){
					if(_borderContainer!=null)_borderContainer.filters=_focusedFilters;
				}
			}
		}
		//绘制边框,边框占据1px
		private function drawBorder(target:Sprite,color:uint,alpha:Number=1,width:Number=1,height:Number=1,round:Number=0):void{
			target.graphics.clear();
			target.graphics.lineStyle(1,color,alpha,true,"none","round");
			target.graphics.drawRoundRect(0,0,width,height,round,round);
		}
		//绘制矩形
		private function drawRect(target:*,thickness:Number=0,color:uint=0,alpha:Number=1,x:Number=0,y:Number=0,width:Number=1,height:Number=1,round:Number=0,filled:Boolean=false):void{
			if((target as Sprite)==null&&(target as Shape)==null){
				throw new Error("target参数应为:Sprite或Shape实例及其子类实例.");
			}
			target.graphics.clear();
			if(width==0||height==0){
				return;
			}
			
			target.graphics.lineStyle(thickness,color,0,false,"none");
			if(filled)
				target.graphics.beginFill(color,alpha);
			target.graphics.drawRoundRect(x,y,width,height,round,round);
			target.graphics.endFill();
		}
		//获得焦点
		private function textFieldFocusIn(e:FocusEvent):void{
			if(_state==FOCUSED)return;
			
			_state=FOCUSED;
			setState(_state);
		}
		//失去焦点
		private function textFieldFocusOut(e:FocusEvent):void{
			if(_state==NORMAL)return;
			
			_state=NORMAL;
			setState(_state);
		}
		//自动适应文本大小时
		private function textFieldChange(e:Event):void{
			this.width=_textField.width+_padding*2;
			this.height=_textField.height+_padding*2;
		}
		//加载外部皮肤完成
		private function thisLoadComplete(e:LoaderEvent):void{
			this.displayStates=e.datas;
			this.removeEventListener(LoaderEvent.LOAD_COMPLETE,thisLoadComplete);
		}
	}
}